# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cegui
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.7
pkgrel=1
pkgdesc="A free library providing windowing and widgets for graphics APIs/engines (mingw-w64)"
arch=('any')
url="http://cegui.org.uk"
license=("MIT")
#makedepends=('doxygen' 'gtk2' 'graphviz' 'irrlicht' 'glm' 'tolua++')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "mercurial")
depends=("${MINGW_PACKAGE_PREFIX}-tinyxml"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-devil"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-FreeImage"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-fribidi"
         "${MINGW_PACKAGE_PREFIX}-glew"
         "${MINGW_PACKAGE_PREFIX}-glfw"
         "${MINGW_PACKAGE_PREFIX}-glm"
         "${MINGW_PACKAGE_PREFIX}-irrlicht"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-lua51"
         "${MINGW_PACKAGE_PREFIX}-ogre3d"
         "${MINGW_PACKAGE_PREFIX}-ois"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-tinyxml"
         #"${MINGW_PACKAGE_PREFIX}-tolua"
         "${MINGW_PACKAGE_PREFIX}-xerces-c"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/crayzedsgui/cegui-${pkgver}.tar.bz2"
        freetype.patch
        mingw-w64-fix.patch
        fix-finding-glew.patch
        fix-finding-directx.patch
        fix-finding-glfw3.patch
        fix-dxerr-libname.patch)
sha256sums=('b351e8957716d9c170612c13559e49530ef911ae4bac2feeb2dacd70b430e518'
            '83e84d862a195c61901b0dd53a1c47434b812fff15fb977f390a45f19dcc4a64'
            '31e666ea015b30b9ee939b69994255eacb2e75fa9dec86538715e4b9a026863a'
            '3aa712304267353afe103cd8efa5f6f7b87fa98423d77610716d15a425194f2e'
            '1ae821516efaeecce5b27579d5236b11b3eb8075d3e173d1b3b973e81c1ee22e'
            '181385b172f952265a0be6a96eccd0ab9d4cb8846f7e07cd5d5e5095a0a591a0'
            '4c22f176f0fa430eeaf2ac6b21d587c7e1f3c04d8d3c03e957a35a95f077531b')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #patch -p1 -i ${srcdir}/freetype.patch
  #patch -p1 -i ${srcdir}/mingw-w64-fix.patch
  patch -p1 -i ${srcdir}/fix-finding-glew.patch
  patch -p1 -i ${srcdir}/fix-finding-directx.patch
  #patch -p1 -i ${srcdir}/fix-finding-glfw3.patch
  patch -p1 -i ${srcdir}/fix-dxerr-libname.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  mkdir $srcdir/build-${MINGW_CHOST}
  cd "$srcdir/build-${MINGW_CHOST}"

  export DXSDK_DIR=${PREFIX_DEPS}/${MINGW_CHOST}
  export CFLAGS="-I${PREFIX_DEPS}/include"
  export CXXFLAGS="-I${PREFIX_DEPS}/include"
  #cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/cmake.exe \
    ../${_realname}-${pkgver} \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCEGUI_LIB_INSTALL_DIR=lib \
    -DCEGUI_BUILD_PYTHON_MODULES=OFF # currently broken :(
    # -PYTHON_EXECUTABLE=/usr/bin/python2
  make
  #make html
}

package() {
  cd "$srcdir/build-${MINGW_CHOST}"
  make -j1 install
}
